package com.china08.yxyapi.api.manage.edu.platform.slider;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.platform.YxyHomeSlider;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.YxyHomeSliderRepository;

import io.swagger.annotations.ApiOperation;

/**
 * 教育局平台办公 焦点图管理 获取
 * 
 */
@CrossOrigin
@RestController
public class SliderGetController extends YxyApiBaseController {

    @Autowired
    private YxyHomeSliderRepository yhsr;

    @ApiOperation(value = "教育局 获取焦点图")
    @ResponseBody
    @RequestMapping(value = "/api_yw/manage/edu/platform/slider/get/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(//
            @PathVariable(value = "id") String id, //
            HttpServletRequest request, //
            HttpServletResponse response) {
        RespModel model = new RespModel();
        String eduId = getProfile(request, response).getSchoolId();
        YxyHomeSlider homeSlider = yhsr.findByIdAndEdbId(id, eduId);
        Assert.notNull(homeSlider, "焦点图未找到");
        model.id = homeSlider.getId();
        model.img = homeSlider.getImg();
        model.url = homeSlider.getUrl();
        model.setMessage("成功");
        return model;
    }

    protected static class RespModel extends YxyApiRespModel {
        public String id;
        public String img;
        public String url;
    }
}
